package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BizPeopleGoods;
import com.ruoyi.business.service.IBizPeopleGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品记录Controller
 * 
 * @author ruoyi
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/business/goodsExchange")
public class BizPeopleGoodsController extends BaseController
{
    @Autowired
    private IBizPeopleGoodsService bizPeopleGoodsService;

    /**
     * 查询商品记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPeopleGoods bizPeopleGoods)
    {
        startPage();
        List<BizPeopleGoods> list = bizPeopleGoodsService.selectBizPeopleGoodsList(bizPeopleGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:export')")
    @Log(title = "商品记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPeopleGoods bizPeopleGoods)
    {
        List<BizPeopleGoods> list = bizPeopleGoodsService.selectBizPeopleGoodsList(bizPeopleGoods);
        list = bizPeopleGoodsService.export(list);
        ExcelUtil<BizPeopleGoods> util = new ExcelUtil<BizPeopleGoods>(BizPeopleGoods.class);
        util.exportExcel(response, list, "商品记录数据");
    }

    /**
     * 获取商品记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:query')")
    @GetMapping(value = "/{userGoodsId}")
    public AjaxResult getInfo(@PathVariable("userGoodsId") Long userGoodsId)
    {
        return success(bizPeopleGoodsService.selectBizPeopleGoodsByUserGoodsId(userGoodsId));
    }

    /**
     * 新增商品记录
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:add')")
    @Log(title = "商品记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPeopleGoods bizPeopleGoods)
    {
        bizPeopleGoods.setCreateBy(getUsername());
        return toAjax(bizPeopleGoodsService.insertBizPeopleGoods(bizPeopleGoods));
    }

    /**
     * 修改商品记录
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:edit')")
    @Log(title = "商品记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPeopleGoods bizPeopleGoods)
    {
        bizPeopleGoods.setUpdateBy(getUsername());
        return toAjax(bizPeopleGoodsService.updateBizPeopleGoods(bizPeopleGoods));
    }

    /**
     * 删除商品记录
     */
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:remove')")
    @Log(title = "商品记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userGoodsIds}")
    public AjaxResult remove(@PathVariable Long[] userGoodsIds)
    {
        return toAjax(bizPeopleGoodsService.deleteBizPeopleGoodsByUserGoodsIds(userGoodsIds));
    }
    @PreAuthorize("@ss.hasPermi('business:goodsExchange:cancel')")
    @Log(title = "取消商品兑换", businessType = BusinessType.DELETE)
    @DeleteMapping("/cancelExchange/{userGoodsIds}")
    public AjaxResult cancelExchange(@PathVariable Long userGoodsIds)
    {
        return toAjax(bizPeopleGoodsService.cancelExchange(userGoodsIds));
    }


}
